<?php
/**
 * Created by PhpStorm.
 * User: hhcyc
 * Date: 2018/4/6
 * Time: 21:42
 */

// http://192.168.10.100:8812/?key=age

$http = new \swoole_http_server("0.0.0.0", 8812);


$http->on('request', function ($request, $response) {
    echo "1\n";
    go(function (){
        echo "2\n";
        \Swoole\Coroutine::sleep(5); // 这里使用\Swoole\Coroutine才能把程序挂起，接收新的请求。如果直接用php原生sleep，是没办法挂起的
        echo "3\n";
    });
    // 获取redis里面的key内容，然后浏览器输出
    $value = $request->get['key'];
    $response->header("Content-Type", "text/plain");
    $response->end("key=>".$value);
});

$http->start();

